﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Base.DAL;
using Base.BLL;
using Base.Util;
using System.Data;
using MPSystem.Models;
using ADX.Views;

namespace MPSystem.Views.YFQ
{
    /// <summary>
    /// DP_test_Condition1.xaml 的交互逻辑
    /// </summary>
    public partial class ZCYLPage_Attac : Page
    {
        public static string parent = "";
        public static int cqbh = 0, gzmbh = 0,xdbh=0;
        public ZCYLPage_Attac()
        {
            InitializeComponent();
            LoadData();
        }

      

        public void LoadData()
        {
            switch(parent)
            {
                case "zc":LoadZc();break;
                case "dblc": LoadDblc(); break;
                case "dbxc": LoadDblc(); break;
                case "mg": LoadMg(); break;
                case "cqyl": LoadCqyl(); break;
            }
        }
        /// <summary>
        /// 加载综采数据
        /// </summary>
        public void LoadZc()
        {
            DataTable tempTable = null;
            #region 读取综采参数明细
            var zccsb = ConfigService.FindZc(cqbh, gzmbh);
            if (zccsb != null)
            {
                tempTable = new DataTable();
                tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
                tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));

                //string str = "起始编号，终止编号，第一通道，第二通道，第三通道,第一通道缸径，" +
                //                "第二通道缸径，第三通道缸径，支架形式,压力上限(MPa),压力下限(MPa)," +
                //                "数据记录周期,压力报警值(MPa),声音报警,短信报警";

                {
                    DataRow dr0 = tempTable.NewRow();
                    dr0["bh"] = "起始编号";
                    dr0["name"] = zccsb.YLFJQSBH;
                    tempTable.Rows.Add(dr0);

                    DataRow dr1 = tempTable.NewRow();
                    dr1["bh"] = "终止编号";
                    dr1["name"] = zccsb.YLFJZZBH;
                    tempTable.Rows.Add(dr1);

                    DataRow dr2 = tempTable.NewRow();
                    dr2["bh"] = "第一通道";
                    dr2["name"] = zccsb.FIRSTTD;
                    tempTable.Rows.Add(dr2);

                    DataRow dr3 = tempTable.NewRow();
                    dr3["bh"] = "第二通道";
                    dr3["name"] = zccsb.SECONDTD;
                    tempTable.Rows.Add(dr3);

                    DataRow dr4 = tempTable.NewRow();
                    dr4["bh"] = "第三通道";
                    dr4["name"] = zccsb.THIRDTD;
                    tempTable.Rows.Add(dr4);

                    DataRow dr5 = tempTable.NewRow();
                    dr5["bh"] = "第一通道缸径(mm)";
                    dr5["name"] = zccsb.FIRSTGJ;
                    tempTable.Rows.Add(dr5);

                    DataRow dr6 = tempTable.NewRow();
                    dr6["bh"] = "第二通道缸径(mm)";
                    dr6["name"] = zccsb.SECONDGJ;
                    tempTable.Rows.Add(dr6);

                    DataRow dr7 = tempTable.NewRow();
                    dr7["bh"] = "第三通道缸径(mm)";
                    dr7["name"] = zccsb.THIRDGJ;
                    tempTable.Rows.Add(dr7);

                    DataRow dr8 = tempTable.NewRow();
                    dr8["bh"] = "支架形式";
                    dr8["name"] = zccsb.ZJXS;
                    tempTable.Rows.Add(dr8);

                    DataRow dr9 = tempTable.NewRow();
                    dr9["bh"] = "压力上限(MPa)";
                    dr9["name"] = zccsb.YLSX;
                    tempTable.Rows.Add(dr9);

                    DataRow dr10 = tempTable.NewRow();
                    dr10["bh"] = "压力下限(MPa)";
                    dr10["name"] = zccsb.YLXX;
                    tempTable.Rows.Add(dr10);

                    DataRow dr11 = tempTable.NewRow();
                    dr11["bh"] = "数据记录周期";
                    dr11["name"] = zccsb.SJJLZQ;
                    tempTable.Rows.Add(dr11);

                    DataRow dr12 = tempTable.NewRow();
                    dr12["bh"] = "压力报警值(MPa)";
                    dr12["name"] = zccsb.YLBJZ;
                    tempTable.Rows.Add(dr12);

                    DataRow dr13 = tempTable.NewRow();
                    dr13["bh"] = "声音报警";
                    if (zccsb.WAVEBJ)
                        dr13["name"] = "是";
                    else
                        dr13["name"] = "否";
                    //dr13["name"] = r.WAVEBJ;
                    tempTable.Rows.Add(dr13);

                    DataRow dr14 = tempTable.NewRow();
                    dr14["bh"] = "短信报警";
                    if (zccsb.DXBJ)
                        dr14["name"] = "是";
                    else
                        dr14["name"] = "否";
                    //dr14["name"] = r.DXBJ;
                    tempTable.Rows.Add(dr14);
                }
                tempTable.AcceptChanges();
                dataGrid.ItemsSource = tempTable.DefaultView;
                tempTable.Dispose();
            }
            #endregion
            #region 读取报警信息
            DataZcService d = new DataZcService();
            var warn = d.GetWarn(cqbh, gzmbh);
            if (warn == null || warn.X.Count == 0) return;
            tempTable = new DataTable();
            tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("datetime", Type.GetType("System.String")));
            for (int i = 0; i < warn.X.Count; i++)
            {
                DataRow dr = tempTable.NewRow();
                dr["bh"] = warn.X[i];
                dr["name"] = warn.S[i];
                dr["datetime"] = warn.T[i].ToString("yyyy-MM-dd HH:mm:ss");
                tempTable.Rows.Add(dr);
            }
            tempTable.AcceptChanges();
            dataGrid2.ItemsSource = tempTable.DefaultView;
            tempTable.Dispose();
            #endregion
        }
        /// <summary>
        /// 加载顶板离层/下沉数据
        /// </summary>
        public void LoadDblc()
        {
            DataTable tempTable = null;
            #region 读取顶板离层/下沉参数明细
            var zccsb = ConfigService.FindDblc(cqbh, xdbh,parent=="dblc");
            if (zccsb != null)
            {
                tempTable = new DataTable();
                tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
                tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
                DataRow dr0 = tempTable.NewRow();
                dr0["bh"] = "测区名称";
                dr0["name"] = zccsb.CQMC;
                tempTable.Rows.Add(dr0);

                DataRow dr1 = tempTable.NewRow();
                dr1["bh"] = "巷道名称";
                dr1["name"] = zccsb.XDMC;
                tempTable.Rows.Add(dr1);

                DataRow dr2 = tempTable.NewRow();
                dr2["bh"] = "传感器起始编号";
                dr2["name"] = zccsb.CGQQSBH;
                tempTable.Rows.Add(dr2);

                DataRow dr3 = tempTable.NewRow();
                dr3["bh"] = "传感器终止编号";
                dr3["name"] = zccsb.CGQZZBH;
                tempTable.Rows.Add(dr3);

                DataRow dr4 = tempTable.NewRow();
                dr4["bh"] = "位移报警值(mm)";
                dr4["name"] = zccsb.WYBJZ;
                tempTable.Rows.Add(dr4);

                DataRow dr5 = tempTable.NewRow();
                dr5["bh"] = "记录周期(分钟)";
                dr5["name"] = zccsb.SJJLZQ;
                tempTable.Rows.Add(dr5);

                tempTable.AcceptChanges();
                dataGrid.ItemsSource = tempTable.DefaultView;
                tempTable.Dispose();
            }
            #endregion
            #region 读取报警信息
            DataDblcService d = new DataDblcService();
            var warn = d.GetWarn(cqbh, xdbh);
            if (warn == null || warn.X.Count == 0) return;
            tempTable = new DataTable();
            tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("datetime", Type.GetType("System.String")));
            for (int i = 0; i < warn.X.Count; i++)
            {
                if ((parent == "dblc" && warn.LX[i] != "LC") || (parent == "dbxc" && warn.LX[i] != "XC")) continue;
                DataRow dr = tempTable.NewRow();
                dr["bh"] = warn.X[i];
                dr["name"] = warn.S[i];
                dr["datetime"] = warn.T[i].ToString("yyyy-MM-dd HH:mm:ss");
                tempTable.Rows.Add(dr);
            }
            tempTable.AcceptChanges();
            dataGrid2.ItemsSource = tempTable.DefaultView;
            tempTable.Dispose();
            #endregion
        }

        /// <summary>
        /// 加载锚杆/索数据
        /// </summary>
        public void LoadMg()
        {
            DataTable tempTable = null;
            #region 读取顶板离层/下沉参数明细
            var zccsb = ConfigService.FindMg(cqbh, xdbh);
            if (zccsb != null)
            {
                tempTable = new DataTable();
                tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
                tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
                DataRow dr0 = tempTable.NewRow();
                dr0["bh"] = "测区名称";
                dr0["name"] = zccsb.CQMC;
                tempTable.Rows.Add(dr0);

                DataRow dr1 = tempTable.NewRow();
                dr1["bh"] = "巷道名称";
                dr1["name"] = zccsb.XDMC;
                tempTable.Rows.Add(dr1);

                DataRow dr2 = tempTable.NewRow();
                dr2["bh"] = "传感器起始编号";
                dr2["name"] = zccsb.CGQQSBH;
                tempTable.Rows.Add(dr2);

                DataRow dr3 = tempTable.NewRow();
                dr3["bh"] = "传感器终止编号";
                dr3["name"] = zccsb.CGQZZBH;
                tempTable.Rows.Add(dr3);

                DataRow dr4 = tempTable.NewRow();
                dr4["bh"] = "锚杆报警值(KN)";
                dr4["name"] = zccsb.MGBJZ;
                tempTable.Rows.Add(dr4);

                DataRow dr5 = tempTable.NewRow();
                dr5["bh"] = "锚索报警值(KN)";
                dr5["name"] = zccsb.MSBJZ;
                tempTable.Rows.Add(dr5);

                DataRow dr6 = tempTable.NewRow();
                dr6["bh"] = "记录周期(分钟)";
                dr6["name"] = zccsb.SJJLZQ;
                tempTable.Rows.Add(dr6);

                tempTable.AcceptChanges();
                dataGrid.ItemsSource = tempTable.DefaultView;
                tempTable.Dispose();
            }
            #endregion
            #region 读取报警信息
            DataMgService d = new DataMgService();
            var warn = d.GetWarn(cqbh, xdbh);
            if (warn == null || warn.X.Count == 0) return;
            tempTable = new DataTable();
            tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("datetime", Type.GetType("System.String")));
            for (int i = 0; i < warn.X.Count; i++)
            {   
                DataRow dr = tempTable.NewRow();
                dr["bh"] = warn.X[i];
                dr["name"] = warn.S[i];
                dr["datetime"] = warn.T[i].ToString("yyyy-MM-dd HH:mm:ss");
                tempTable.Rows.Add(dr);
            }
            tempTable.AcceptChanges();
            dataGrid2.ItemsSource = tempTable.DefaultView;
            tempTable.Dispose();
            #endregion
        }
        /// <summary>
        /// 加载超前应力数据
        /// </summary>
        public void LoadCqyl()
        {
            DataTable tempTable = null;
            #region 读取超前应力参数明细
            var zccsb = ConfigService.FindCqyl(cqbh, xdbh);
            if (zccsb != null)
            {
                tempTable = new DataTable();
                tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
                tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
                DataRow dr0 = tempTable.NewRow();
                dr0["bh"] = "测区名称";
                dr0["name"] = zccsb.CQMC;
                tempTable.Rows.Add(dr0);

                DataRow dr1 = tempTable.NewRow();
                dr1["bh"] = "巷道名称";
                dr1["name"] = zccsb.XDMC;
                tempTable.Rows.Add(dr1);

                DataRow dr2 = tempTable.NewRow();
                dr2["bh"] = "传感器起始编号";
                dr2["name"] = zccsb.CGQQSBH;
                tempTable.Rows.Add(dr2);

                DataRow dr3 = tempTable.NewRow();
                dr3["bh"] = "传感器终止编号";
                dr3["name"] = zccsb.CGQZZBH;
                tempTable.Rows.Add(dr3);

                DataRow dr4 = tempTable.NewRow();
                dr4["bh"] = "记录周期(分钟)";
                dr4["name"] = zccsb.SJJLZQ;
                tempTable.Rows.Add(dr4);

                tempTable.AcceptChanges();
                dataGrid.ItemsSource = tempTable.DefaultView;
                tempTable.Dispose();
            }
            #endregion
            #region 读取报警信息
            DataCqylService d = new DataCqylService();
            var warn = d.GetWarn(cqbh, xdbh);
            if (warn == null || warn.X.Count == 0) return;
            tempTable = new DataTable();
            tempTable.Columns.Add(new DataColumn("bh", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("name", Type.GetType("System.String")));
            tempTable.Columns.Add(new DataColumn("datetime", Type.GetType("System.String")));
            for (int i = 0; i < warn.X.Count; i++)
            {
                DataRow dr = tempTable.NewRow();
                dr["bh"] = warn.X[i];
                dr["name"] = warn.S[i];
                dr["datetime"] = warn.T[i].ToString("yyyy-MM-dd HH:mm:ss");
                tempTable.Rows.Add(dr);
            }
            tempTable.AcceptChanges();
            dataGrid2.ItemsSource = tempTable.DefaultView;
            tempTable.Dispose();
            #endregion
        }
    }
}
